<?php

namespace common\service;

use common\exception\LogicException;
use common\service\export_business_excel_logic\AssetList;
use common\service\export_business_excel_logic\ExportLogicInterface;
use common\service\export_business_excel_logic\ShotList;
use support\ErrorCode;
use support\SingletonTrait;

class ExportBusinessExcelService
{
    use SingletonTrait;

    /** @var ExportLogicInterface[] $codeLogicMap */
    protected $codeLogicMap = [];

    public function __construct()
    {
        $this->codeLogicMap['shot_list'] = ShotList::getInstance();
        $this->codeLogicMap['asset_list'] = AssetList::getInstance();
    }

    /**
     * 导出业务表格
     * @param $businessCode
     * @param $exportParam
     * @return \PhpOffice\PhpSpreadsheet\Spreadsheet
     */
    public function exportBusinessCodeExcel($businessCode, $exportParam)
    {
        if (empty($this->codeLogicMap[$businessCode])) {
            throw new LogicException("{$businessCode} not support", ErrorCode::DATA_INVALID);
        }
        return $this->codeLogicMap[$businessCode]->process($exportParam);
    }
}
